Skip to content

feat: add a partition setting to Speakeasy processes - #9319

Merged
bflad merged 4 commits into
mainfrom
bflad/age-3680-feat-add-a-partition-setting-to-gram
Nov 21, 2026
Merged

bflad merged 4 commits into
mainfrom
bflad/age-3680-feat-add-a-partition-setting-to-gram

Conversation

@bflad

@bflad bflad commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Linear: AGE-3680

Important

Merge order: every process now refuses to start without GRAM_PARTITION. speakeasy-api/gram-infra#5691 (merged and applied) sets it on all Gram workloads, and it is confirmed synced to the dev and prod workloads, so this PR is safe to merge.

Summary

  • New server/internal/partition package: a closed Partition enum (us, eu) with Parse and Names. Adding a partition is a code change, so a typo in configuration fails at startup.
  • Required global --partition flag (GRAM_PARTITION) on the server binary, with no default: the root Before hook validates it, records it in the context and adds gram.partition to the base logger, so every command (start, mcp, worker, streams, admin, the network ingress and tailnet gateway commands, seeds) requires it and logs it without registering the flag itself. A missing, empty or unknown value stops every command at startup; gram version and help output still work without it.
  • Traces and metrics: o11y.SetupOTelSDKOptions gains Partition, added to the OTel resource shared by the tracer and meter providers. All nine callers pass PullPartition(ctx), and SetupOTelSDK rejects an empty partition so a future caller cannot silently emit gram.partition="".
  • pystreams: a required --partition option (GRAM_PARTITION) restricted to the same values, added to its log attributes and OTel resource. Click treats a set but empty value as missing, so it fails the same way as Go, and an explicit --partition wins over the environment as it does in Go.
  • Tunnel gateway: requires and validates GRAM_PARTITION and adds gram.partition to its logs (it has no OTel pipeline).
  • Local development: mise.toml sets GRAM_PARTITION = "us" next to GRAM_ENVIRONMENT, so pitchfork, mise tasks and CI keep working.

Motivation

Speakeasy is moving to independent production partitions (the existing US deployment plus an EU one). The WorkOS partition rules, the cross-partition login redirect and partition-aware names all need each process to know its partition, and telemetry from different partitions needs to be distinguishable. GRAM_ENVIRONMENT stays prod in both partitions because CORS and the live API key prefix depend on it, so the partition is a separate setting.

The setting has no default on purpose: a fallback to us would let a new or misconfigured deployment silently run as the wrong partition, which matters most for the EU deployment. Requiring it everywhere turns that mistake into a startup failure. The setting that lists other partitions' dashboard URLs is deferred to AGE-3684, its only consumer. The companion gram-infra changes set GRAM_PARTITION on every workload, tag the Datadog agents, add the partition to deployment notifications, and make the Terraform variable and Helm value required as well.

https://linear.app/speakeasy/issue/AGE-3680/feat-add-a-partition-setting-to-gram-processes

The server binary, pystreams and the tunnel gateway read GRAM_PARTITION (us or eu, default us) and fail at startup on an unknown or empty value. The server binary takes it as a global flag, so every command tags its logs with gram.partition, and o11y.SetupOTelSDK adds it to the trace and metric resource and rejects an empty partition. pystreams adds it to its log attributes and OTel resource. The tunnel gateway adds it to its logs.

US runs with the default, so nothing else changes. The setting that lists other partitions' site URLs moved to AGE-3684, its only consumer.
@bflad bflad added enhancement New feature or request go Pull requests that update go code labels Nov 19, 2026
@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c63f858

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
server Minor
tunnel Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@linear-code

linear-code Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

AGE-3680

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

2 issues found across 29 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="server/cmd/gram/flags_partition_test.go">

<violation number="1" location="server/cmd/gram/flags_partition_test.go:58">
P3: These two env-var tests call `t.Setenv` without the `//nolint:paralleltest` annotation that the rest of this file and the package use. Add the same annotation so the paralleltest linter does not flag them.</violation>
</file>

<file name="tunnel/cmd/tunnel-gateway/main.go">

<violation number="1" location="tunnel/cmd/tunnel-gateway/main.go:33">
P3: This duplicates the closed partition set from `server/internal/partition`, so adding a partition means editing two places. The comment's reason is also off: this is the same Go module, and the blocker is Go's `internal` visibility rule. Move the set to a non-internal package that both binaries import, and use an explicit default constant instead of `knownPartitions[0]`.</violation>
</file>

Linked issue analysis

Linked issue: AGE-3680: feat: add a partition setting to Gram processes

Status Acceptance criteria Notes
✅ Default to us and reject invalid partition values at startup The Go server, pystreams, and tunnel gateway default to us and reject empty or unknown values.
✅ Add gram.partition to process logs The server root logger, pystreams logger, and tunnel gateway logger all receive the partition attribute.
✅ Add gram.partition to server and pystreams telemetry Both OTel resource builders include the partition, so their spans and metrics carry the attribute.

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread tunnel/cmd/tunnel-gateway/main_test.go Resolved
Comment thread server/cmd/gram/flags_partition_test.go Resolved
Comment thread pystreams/tests/test_partition.py Resolved
Comment thread tunnel/cmd/tunnel-gateway/main.go Resolved
https://linear.app/speakeasy/issue/AGE-3680/feat-add-a-partition-setting-to-gram-processes

An explicit --partition now wins over an empty GRAM_PARTITION in pystreams, as it does in Go. The pystreams tests clear any ambient GRAM_PARTITION, the tunnel gateway names its default partition explicitly, and its rejection tests are table driven.
@bflad
bflad marked this pull request as ready for review November 19, 2026 19:21
@bflad
bflad requested a review from a team as a code owner November 19, 2026 19:21
https://linear.app/speakeasy/issue/AGE-3680/feat-add-a-partition-setting-to-gram-processes

The server binary, pystreams and the tunnel gateway now refuse to start when GRAM_PARTITION is missing, instead of falling back to us, so a deployment that forgets it cannot silently run as the wrong partition. gram version and help output still work without it. Local development sets GRAM_PARTITION=us in mise.toml, and every deployed workload already receives it from the gram-infra Helm chart.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 12 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread server/cmd/gram/flags_partition.go Resolved
https://linear.app/speakeasy/issue/AGE-3680/feat-add-a-partition-setting-to-gram-processes

Arguments after "--" are positional, so a --help or -h there no longer exempts a command from requiring GRAM_PARTITION.
@bflad

bflad commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Confirmed that this is okay to merge.

@bflad
bflad added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 635e382 Nov 21, 2026
59 checks passed
@bflad
bflad deleted the bflad/age-3680-feat-add-a-partition-setting-to-gram branch November 21, 2026 18:05
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants